# -*- coding: utf-8 -*-
# author:HHR
# time:2021/2/21:8:50
# ___msg___ = '创建年费任务'

from Db_connect import DB_connect
import redis


class create_big_tasK():
    def __init__(self):
        self.mysql_con = DB_connect().online_big_data()
        self.mysql_cur = self.mysql_con.cursor()
        self.online_con = DB_connect().online_big_data()
        self.big_cur = self.online_con.cursor()
        self.redis_con = redis.Redis(host='127.0.0.1', password="xhhg123456", port=6379, db=2, decode_responses=True)
        # self.redis_con = redis.Redis(host='121.4.69.146', password='xhhg123456',
        #                 port=6389, db=2, decode_responses=True)

    # def get_sqh(self):
    #     sql = "SELECT DISTINCT application_number FROM ccy_paid GROUP BY application_number"
    #     try:
    #         self.big_cur.execute(sql)
    #     except Exception as E:
    #         print("查询错误！", E)
    #     all_data_1 = self.big_cur.fetchall()
    #     for item in all_data_1:
    #         self.redis_con.sadd("协和端口查询", item[0])

    def big_task(self):
        sql = "select distinct application_number from xhhg_pantent_status_0723"
        try:
            self.mysql_cur.execute(sql)
        except Exception as E:
            print("查询错误！", E)
        all_data = self.mysql_cur.fetchall()
        for one_data in all_data:
            print(one_data[0])
            self.redis_con.sadd("外部接口查询", one_data[0])

    def updata_today_data(self):
        select_sql = "select distinct application_number from xhhg_pantent_status_0517"
        try:
            self.mysql_cur.execute(select_sql)
        except Exception as E:
            print("查询错误！", E)
        all_data = self.mysql_cur.fetchall()
        for one_data in all_data:
            select_sql1 = f"select agency, fmr, first_agent from xhhg_pantent_status where application_number='ZL{one_data[0]}'"
            self.mysql_cur.execute(select_sql1)
            all_data1 = self.mysql_cur.fetchall()
            if all_data1:
                updata_sql = f"UPDATE `xhhg_pantent_status_0517` SET agency='{all_data1[0][0]}', fmr='{all_data1[0][1]}', first_agent='{all_data1[0][2]}' WHERE application_number='{one_data[0]}'"
                print(updata_sql)
                self.mysql_cur.execute(updata_sql)
                self.mysql_con.commit()

    def main(self):
        # self.updata_today_data()
        self.big_task()
        # self.get_sqh()
        self.mysql_cur.close()
        self.mysql_con.close()
        self.big_cur.close()
        self.online_con.close()


if __name__ == '__main__':
    create_big_tasK().main()
